<template>
  <div>
    <!-- 车型信息搜索 -->
    <TopFilter
      :list="topFilterInit"
      :cols="3"
      :collapse="collapse"
      labelWidth="50"
      @filterChange="changeHandle"
    ></TopFilter>
    <!-- table -->
    <FilterTable
      height="250"
      ref="listModal"
      :columns="columns"
      :selectionType="selectType"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
      :onRowSelectChange="selectChange"
        columnsRef="cms-common_model_index_01"  
    
    ></FilterTable>
    <div class="dialogBottmView">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button @click="saveDialog" type="primary">{{submit}}</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getBrand, getSeries, getModelPage, toSelectData } from '@/api/cms-common/basedata';
export default {
  mixins: [dictionary],
  props: {
    submit: {
      type: String,
      default: '确定'
    },
    selectType:{
      type: String,
      default: 'multiple'
    }
  },
  data() {
    return {
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchApi: getModelPage,
      fetchParams: {'isVehicleSalesBrand':10041001}, //ipa 接口
      selectedRows: [] //选中物料
    };
  },
  methods: {
    //搜索数据
    topFilterInitFun() {
      return [
        {
          type: 'SELECT',
          label: '品牌',
          fieldName: 'brandId',
          placeholder: '请输入',
          initialValue: '',
          itemList: [],
          change: val => {
            this.loadSeries(val);
          }
        },
        {
          type: 'SELECT',
          label: '车系',
          fieldName: 'seriesId',
          placeholder: '请输入',
          initialValue: '',
          itemList: []
        }
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({'isVehicleSalesBrand':10041001},val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '品牌', dataIndex: 'brandName', sorter: true },
        { title: '车系', dataIndex: 'seriesName', sorter: true },
        { title: '车型代码', dataIndex: 'modelCode', sorter: true },
        { title: '车型名称', dataIndex: 'modelName', sorter: true }
      ];
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      console.log(this.selectedRows);
    },
    //保存
    saveDialog() {
      if(this.selectedRows==null||this.selectedRows.length==0){
        this.$notify.error({title: '提示信息',message:'请选择数据!'});
      }else{
        this.$emit('close', { visible: false, data: this.selectedRows });
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false});
    },
    async loadBrand() {
      // let b = await getBrand({});
      let b = await getBrand({'isVehicleSalesBrand':10041001});
      this.topFilterInit[0].itemList = toSelectData(b.data, 'brandId', 'brandName');
    },
    async loadSeries(brandId) {
      this.topFilterInit[1].initialValue = '';
      let s = await getSeries({ brandId: brandId });
      this.topFilterInit[1].itemList = toSelectData(s.data, 'seriesId', 'seriesName');
    }
  },
  mounted() {
    this.loadBrand();
    //this.BaseTable = this.$refs.listModal.$refs.pageTable;
  }
};
</script>

<style lang="less" scoped>
</style>
